package com.code.day12;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;

public class Day12ExceptionThrows {
    public static void main(String[] args) {
        String s = "abc.txt1";
        String num = null;
        /*
          调用处相当于接收了一个下面抛上来的一个
          FileNotFoundException(编译时期异常)
         */
        try {
            insert(s);
            insert(num);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            System.out.println(e.toString());
            System.out.println(e.getMessage());
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            System.out.println("我一定会回来的");
        }

        delete();
        update();
        select();
    }

    private static void select() {
        System.out.println("查询功能");
    }

    private static void update() {
        System.out.println("修改功能");
    }

    private static void delete() {
        System.out.println("删除功能");
    }

    /**
     * 假设insert方法是一个添加功能
     *
     * @param s
     */
    private static void insert(String s) throws FileNotFoundException,IOException{
        if(s==null){
            throw new IOException("文件名不能为空");
        }
        if (!s.endsWith(".txt")) {
            //创建异常对象
            throw new FileNotFoundException("文件找不到了");
        }
        System.out.println("添加功能");
    }
}
